//
//  UIView+HDChooseComView.m
//  app
//
//  Created by D on 15/8/27.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDChooseComView.h"

static const CGFloat kMargin = 30.0f;
static const CGFloat kButtonH = 50.0f;


@implementation HDChooseComView

-(id)initWithChoose:(HDMyCommunityModel*)model
{
    if (self = [super init]) {
        
        self.frame = CGRectMake(0, 0, UBO_WINDOW.width, UBO_WINDOW.height);
        self.userInteractionEnabled = YES;
//        self.backgroundColor = [UIColor clearColor];
//        self.alpha = 0.8;
        
        UIView * mainView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, UBO_WINDOW.width, UBO_WINDOW.height)];
        self.backgroundColor = [UIColor blackColor];
        self.alpha = 0.8;
        [self addSubview:mainView];
        
        
        CGFloat buttonW = UBO_WINDOW.width - 2*kMargin;
        
        HDChooseButton * chooseBtn = [[HDChooseButton alloc]initWithFrame:CGRectOf([self.ubo fx:UB_1_2 ox:-buttonW/2 fy:UB_1_2 oy:-kButtonH], [self.ubo ow:buttonW oh:kButtonH])];
        [chooseBtn setTitle:@"进入该小区" forState:UIControlStateNormal];
        [chooseBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        chooseBtn.backgroundColor = [UIColor whiteColor];
        chooseBtn.tag = 1;
        chooseBtn.cmid = model.cmid;
        chooseBtn.house_id = model.house_id;
        chooseBtn.community = model.community_name;
        chooseBtn.house_name = model.house_name;
        [chooseBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
        [chooseBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
        [self addSubview:chooseBtn];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectOf([chooseBtn.ufo fx:0 fy:1 ], [self.ubo ow:buttonW oh:0.3])];
        
        line.alpha = 0.25;
        line.backgroundColor = [UIColor whiteColor];
        [self addSubview:line];
        
        
        HDChooseButton * cancleBtn = [[HDChooseButton alloc]initWithFrame:CGRectOf([chooseBtn.ufo fx:0 fy:1 oy:0.3], [self.ubo ow:buttonW oh:kButtonH])];
        [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        cancleBtn.backgroundColor = [UIColor whiteColor];
        cancleBtn.tag = 2;
        [cancleBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
        [cancleBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
        [self addSubview:cancleBtn];
        
        
        
        
        
    }
    return self;
}

-(void)chooseBtn:(HDChooseButton*)sender
{
    if (self.delegate  && [self.delegate respondsToSelector:@selector(cellChooseWithButton:)]) {
        [self.delegate cellChooseWithButton:sender];
    }
}

@end
